package snapex.core.controller;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import snapex.ServerConfiguration;

@Component
public class ResponseHeaderFilter implements Filter{

	@Autowired
	ServerConfiguration serverConfig;
	
	@Override
	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
			throws IOException, ServletException {
		
		  HttpServletResponse response = (HttpServletResponse) servletResponse;
		  
          response.setHeader("x-snapex-oauth", serverConfig.getUrl());
          
          filterChain.doFilter(servletRequest, servletResponse);		
	}
}
